"""
Case Type   : 资源池化系统视图
Case Name   : 默认配置下查看系统视图dbe_perf.track_memory_context_detail
Create At   : 2025/2
Owner       : haomeng
Description :
    1、主节点查看系统表dbe_perf.track_memory_context_detail中DMSDrcContext字段是否存在
    2、备节点查看系统表dbe_perf.track_memory_context_detail中DMSDrcContext字段是否存在
Expect      :
    1、无相关信息
    2、无相关信息
History     :
"""

import os
import unittest

from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger


class ShareStorageSystemView(unittest.TestCase):

    def setUp(self):
        self.log = Logger()
        self.log.info(f'----{os.path.basename(__file__)} start----')
        self.prish = CommonSH('PrimaryDbUser')
        self.stash = CommonSH('Standby1DbUser')
        self.constant = Constant()

        self.sys_view1 = 'dbe_perf.track_memory_context'
        self.sys_view2 = 'dbe_perf.track_memory_context_detail()'

    def test_ss_system_view(self):
        text = '-----step1:主节点查看系统表dbe_perf.track_memory_context_detail中' \
               'DMSDrcContext字段是否存在  expect:无相关信息-----'
        self.log.info(text)

        sql1 = f"select * from {self.sys_view1}('DMSDrcContext');"
        self.log.info(sql1)
        res1 = self.prish.execut_db_sql(sql1)
        self.log.info(res1)
        self.assertEqual('t', res1.splitlines()[-2].strip(), '存在异常信息')

        res1_2 = self.prish.execut_db_sql(f"select * from {self.sys_view2};",
                                          dbname='postgres')
        self.log.info(res1_2)
        self.assertIn('(0 rows)', res1_2, '存在异常信息')

        text = '-----step2:备节点查看系统表dbe_perf.track_memory_context_detail中' \
               'DMSDrcContext字段是否存在  expect:无相关信息-----'
        self.log.info(text)

        res2 = self.prish.execut_db_sql(sql1)
        self.log.info(res2)
        self.assertEqual('t', res2.splitlines()[-2].strip(), '存在异常信息')

        res2_2 = self.stash.execut_db_sql(f"select * from {self.sys_view2};",
                                          dbname='postgres')
        self.log.info(res2_2)
        self.assertIn('(0 rows)', res2_2, '存在异常信息')

    def tearDown(self):
        self.log.info('----No need to clean----')
        self.log.info(f'----{os.path.basename(__file__)} end----')
